package com.domain.beanutil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/** 
* @ClassName: DateUtil 
* @Description: TODO(这里用一句话描述这个类的作用) 
* @author wangxm
* @date 2014-6-16 下午4:17:47 
*/

public class DateUtil {
	
//	public final static String jdkDateFormat = "yyyy-MM-dd";
//	
//	public final static String jdkDateTimeFormat = "yyyy-MM-dd HH:mm:ss";
	
	public static Date strToDate(String strDate){
	    SimpleDateFormat dateFormat = new SimpleDateFormat(DataUtilInterface.jdkDateFormat);
	    Date date = null;
	    
	    if(strDate == null){
	    	return null;
	    }
	    
	    try{
	      date = dateFormat.parse(strDate);
	    }catch(ParseException e){
	    	e.printStackTrace();
	    }
	    return date;
    }

	public static Date strToDateTime(String strDateTime){
	    SimpleDateFormat dateTimeFormat = new SimpleDateFormat(DataUtilInterface.jdkDateTimeFormat);
	    Date dateTime = null;
	    
	    if(strDateTime == null){
	    	return null;
	    }
	    
	    try {
	    	dateTime = dateTimeFormat.parse(strDateTime);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	    return dateTime;
	}
	
	public static String dateToStr(Date date){
	    SimpleDateFormat dateFormat = new SimpleDateFormat(DataUtilInterface.jdkDateFormat); 
	    String strDate = "";
	    
	    if(date != null){
	    	strDate = dateFormat.format(date);
	    }else{
	    	return null;
	    }
	    return strDate;
	}
	
    public static String dateTimeToStr(Date date){
       SimpleDateFormat dateTimeFormat = new SimpleDateFormat(DataUtilInterface.jdkDateTimeFormat); 
       String strDateTime = "";
       if(date != null){
    	   strDateTime = dateTimeFormat.format(date);
       }else{
    	   return null;
       }
       return strDateTime;
    }

}
